package com.gem.netty.service.nobility;

import com.gem.entity.Game;
import com.gem.entity.Nobility;
import com.gem.enums.ClientMessageType;
import com.gem.enums.MessageColorType;
import com.gem.factory.game.GameFactory;
import com.gem.netty.entity.ClientContent;
import com.gem.netty.entity.CurrentUser;
import com.gem.pipeline.BusinessProcess;
import com.gem.pipeline.ProcessContext;
import com.gem.utils.R;

/**
 * Author: Xhy
 * CreateTime: 2022-09-25 13:46
 * 是否可以兑换贵族
 */
public class IsSwapNobilityService implements BusinessProcess<ClientContent> {

    @Override
    public void process(ProcessContext<ClientContent> context) {
        Game game = GameFactory.get(context.getData().getRoomId());
        CurrentUser user = game.getUsers().get(game.getCurrentIndex());
        // 获取兑换贵族卡的信息
        Nobility nobility = Nobility.get(context.getData().getContent().getNobility().getNo());
        nobility.getCards().forEach((k,v)->{
            if ((user.getCards().get(k).size() - v ) < 0){
                context.setNeedBreak(true);
                context.setResult(R.error().data("color", MessageColorType.SYSTEM_MESSAGE.type).message("换不了贵族,卡牌不够").type(ClientMessageType.GET_NOBILITY.type));
                return;
            }
        });
    }

}
